home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F29328_PSsWizard.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-10  |  11.5 KB  |  492 lines

  1. // PSsWizard.cpp : Implementation of CPSsWizard
  2. #include "stdafx.h"
  3. #include "TCPssWiz.h"
  4. #include "PSsWizard.h"
  5. #include "PaperSpaceWizard.h"
  6.  
  7. #include "xdbtool_i.c"
  8. #include "imsigx_i.c"
  9. #include "gxmps_i.c"
  10.  
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CPSsWizard
  13.  
  14. COleVariant t(-1L, VT_BOOL);
  15. COleVariant f(0L, VT_BOOL);
  16. COleVariant missing((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. STDMETHODIMP CPSsWizard::get_ClassID(BSTR *pVal)
  22. {
  23.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  24.     HRESULT hRes = E_FAIL;
  25.     LPOLESTR olestr = NULL;
  26.  
  27.     try
  28.     {
  29.         if(SUCCEEDED( ::StringFromCLSID(CLSID_PSsWizard, &olestr)))
  30.         {
  31.             *pVal = ::SysAllocString(olestr);
  32.             hRes = S_OK;
  33.         }
  34.     }
  35.     catch (...)
  36.     {
  37.         TRACE_EXCEPTION("CPSsWizard::get_ClassID")
  38.     }
  39.  
  40.     if (olestr != NULL)
  41.     CoTaskMemFree(olestr);
  42.  
  43.     return hRes;
  44. }
  45.  
  46. STDMETHODIMP CPSsWizard::get_Description(BSTR *pVal)
  47. {
  48.     // Get the description from the resource
  49.     HRESULT hRes = E_FAIL;
  50.     CString strResult;
  51.     if (strResult.LoadString(IDS_DESCRIPTION))
  52.     {
  53.         *pVal = strResult.AllocSysString();
  54.         hRes = S_OK;
  55.     }
  56.     return hRes;
  57. }
  58.  
  59. STDMETHODIMP CPSsWizard::GetToolInfo(VARIANT *CommandNames, VARIANT *MenuCaptions, VARIANT *StatusPrompts, VARIANT *ToolTips, VARIANT *Enabled, VARIANT *WantsUpdates, long *ret)
  60. {
  61.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  62.     HRESULT hRes = E_FAIL;
  63.     
  64.     SAFEARRAYBOUND bound = {NUM_TOOLS, 0};
  65.  
  66.     CString cstrText;
  67.     CString cstrTextTemp;
  68.  
  69.     BSTR bstrCommandName = NULL;
  70.     BSTR bstrMenuCaption = NULL;
  71.     BSTR bstrStatusPrompt = NULL;
  72.     BSTR bstrToolTip = NULL;
  73.     BOOL bEnabled = TRUE;
  74.     BOOL bWantsUpdates = TRUE;
  75.  
  76.     
  77.     long lIndicies = 0;
  78.     try
  79.     {
  80.         
  81.         hRes = SafeArrayRedim(CommandNames->parray, &bound);
  82.         CHECK_HRESULT(hRes)
  83.  
  84.         hRes = SafeArrayRedim(MenuCaptions->parray, &bound);
  85.         CHECK_HRESULT(hRes)
  86.  
  87.         hRes = SafeArrayRedim(StatusPrompts->parray, &bound);
  88.         CHECK_HRESULT(hRes)
  89.  
  90.         hRes = SafeArrayRedim(ToolTips->parray, &bound);
  91.         CHECK_HRESULT(hRes)
  92.  
  93.         hRes = SafeArrayRedim(Enabled->parray, &bound);
  94.         CHECK_HRESULT(hRes)
  95.  
  96.         hRes = SafeArrayRedim(WantsUpdates->parray, &bound);
  97.         CHECK_HRESULT(hRes)
  98.  
  99. // AALB 141199        CString cstrText="Insert|Dimension|Tolerance"; 
  100.         cstrText.LoadString (IDS_MAINMENU);
  101.         cstrText.Insert(cstrText.GetLength (), '|');
  102.         cstrTextTemp.LoadString (IDS_SUBMENU);
  103.         cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
  104.         cstrText.Insert(cstrText.GetLength (), '|');
  105.         cstrTextTemp.LoadString (IDS_MENUCAPTION);
  106.         cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
  107.         cstrTextTemp.Empty ();
  108.  
  109.         bstrCommandName = cstrText.AllocSysString();
  110.         hRes = SafeArrayPutElement(CommandNames->parray, &lIndicies, (void *)bstrCommandName);
  111.         CHECK_HRESULT(hRes)
  112.  
  113.         cstrText.Empty ();
  114. // AALB 141199 move this string to resource        cstrText="Tolerance"; 
  115.         cstrText.LoadString (IDS_MENUCAPTION); 
  116.         bstrMenuCaption = cstrText.AllocSysString();
  117.         hRes = SafeArrayPutElement(MenuCaptions->parray, &lIndicies, (void *)bstrMenuCaption);
  118.         CHECK_HRESULT(hRes)
  119.         cstrText.Empty ();
  120.  
  121.          cstrText.LoadString (IDS_PROMT0);
  122.         bstrStatusPrompt = cstrText.AllocSysString();
  123.         hRes = SafeArrayPutElement(StatusPrompts->parray, &lIndicies, (void *)bstrStatusPrompt);
  124.         CHECK_HRESULT(hRes)
  125.         cstrText.Empty ();
  126. // AALB 141199        cstrText="Insert tolerance symbol"; 
  127.         cstrText.LoadString (IDS_TOOLTIPS);; 
  128.         bstrToolTip = cstrText.AllocSysString();
  129.         hRes = SafeArrayPutElement(ToolTips->parray, &lIndicies, (void *)bstrToolTip);
  130.         CHECK_HRESULT(hRes)
  131.  
  132.         hRes = SafeArrayPutElement(Enabled->parray, &lIndicies, (void *)&bEnabled);
  133.         CHECK_HRESULT(hRes)
  134.  
  135.         hRes = SafeArrayPutElement(WantsUpdates->parray, &lIndicies, (void *)&bWantsUpdates);
  136.         CHECK_HRESULT(hRes)
  137.  
  138.         *ret = NUM_TOOLS;
  139.     }
  140.     catch (...)
  141.     {
  142.         if (SUCCEEDED(hRes))
  143.             hRes = E_FAIL;
  144.         TRACE_EXCEPTION("CPSsWizard::GetToolInfo")
  145.     }
  146.     return hRes;
  147. }
  148.  
  149. STDMETHODIMP CPSsWizard::GetPicture(VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, IDispatch **ret)
  150. {
  151.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  152.     LPTSTR IDB = 0;
  153.  
  154.     HRESULT hRes = E_FAIL;
  155.     //    CBitmap pBmp;
  156.     try
  157.     {
  158. //        pBmp.LoadBitmap (IDB_BMP1);
  159.         if(LargeButtons)
  160.         {
  161.             IDB = MAKEINTRESOURCE(IDB_BMP2);
  162.         }
  163.         else
  164.         {
  165.             IDB = MAKEINTRESOURCE(IDB_BMP1);
  166.         }
  167.         HBITMAP pBmp = ::LoadBitmap(AfxGetResourceHandle(), IDB);
  168.  
  169.         PICTDESC pict;
  170.         pict.cbSizeofstruct = sizeof(pict);
  171.         pict.picType = PICTYPE_BITMAP;
  172.         pict.bmp.hbitmap = pBmp;
  173.         pict.bmp.hpal = NULL;
  174.  
  175.         hRes = OleCreatePictureIndirect(&pict, IID_IDispatch, TRUE, (void**)ret);
  176.  
  177.         CHECK_HRESULT(hRes)
  178.         hRes = S_OK;
  179.  
  180.         
  181.     }
  182.  
  183.     catch (...)
  184.     {
  185.         TRACE_EXCEPTION("CPSsWizard::GetPicture")
  186.     }
  187.  
  188.     return hRes;
  189. }
  190.  
  191. STDMETHODIMP CPSsWizard::CopyBitmap(VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, VARIANT_BOOL *ret)
  192. {
  193.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  194.  
  195.     // TODO: Add your implementation code here
  196.  
  197.     return S_OK;
  198. }
  199.  
  200. STDMETHODIMP CPSsWizard::UpdateToolStatus(IDispatch *ThisTool, VARIANT_BOOL *Enabled, VARIANT_BOOL *Checked, VARIANT_BOOL *ret)
  201. {
  202.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  203.  
  204.     // TODO: Add your implementation code here
  205.  
  206.     return S_OK;
  207. }
  208.  
  209. STDMETHODIMP CPSsWizard::Initialize(IDispatch *ThisTool, VARIANT_BOOL *ret)
  210. {
  211.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  212.  
  213.     // TODO: Add your implementation code here
  214.  
  215.     return S_OK;
  216. }
  217.  
  218. STDMETHODIMP CPSsWizard::Terminate(IDispatch *ThisTool)
  219. {
  220.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  221.  
  222.     // TODO: Add your implementation code here
  223.  
  224.     return S_OK;
  225. }
  226.  
  227. STDMETHODIMP CPSsWizard::Run(IDispatch *ThisTool, VARIANT_BOOL *ret)
  228. {
  229.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  230.     HRESULT hRes = E_FAIL;
  231.  
  232.  
  233.     Tool *pTool = NULL;
  234.     IApplication *pIApp = NULL;
  235.     Graphics* pGrs = NULL;
  236.     IDrawing *pDr = NULL;
  237.     long lPsscount = 0;
  238.     COleVariant varAperture(0.2);
  239.  
  240.     COleVariant varOptional(varMissing);
  241.     COleVariant varType((const long)imsiPolyline);
  242.     COleVariant varItem = (0L);
  243.     PaperSpaces *pPss = NULL;
  244.  
  245.     CString cstrText;
  246.     BSTR bstrStatusPrompt;
  247.     cstrText.LoadString (IDS_PROMT);
  248.     bstrStatusPrompt = cstrText.AllocSysString();
  249.     m_bDragging  = FALSE;
  250. //    COleVariant varType((const long)imsiGroup);
  251.     COleVariant varProp;
  252.     Properties *pProps = NULL;
  253.     Property *pProp = NULL;
  254.     IDispatch *pIDisp = NULL;
  255.     PAPERSPACEINFO pPSInfo;
  256.  
  257.     PaperSpace *pPs = NULL;
  258.     IDispatch *pDisp = NULL;
  259.     
  260.     if(m_bRunned)
  261.         return S_OK;
  262.     try
  263.     {
  264.  
  265.         hRes = ThisTool->QueryInterface(IID_Tool, (void **)&m_pTool);
  266.         CHECK_HRESULT(hRes)
  267.  
  268.         hRes = m_pTool->get_Application(&m_pIApplication);
  269.         CHECK_HRESULT(hRes)
  270.  
  271.         hRes = QueryInterface(IID_IPSsWizard, (void**)&m_pITool);
  272.         CHECK_HRESULT(hRes)
  273.         hRes = m_pIApplication->get_ActiveDrawing(&pDr);
  274.         CHECK_HRESULT(hRes)
  275.  
  276.         hRes = pDr->get_PaperSpaces(&pIDisp);
  277.         CHECK_HRESULT(hRes);
  278.         hRes = pIDisp->QueryInterface (IID_PaperSpaces,(void**)&pPss);
  279.         CHECK_HRESULT(hRes);
  280.  
  281.         hRes = pPss->get_Count(&lPsscount);
  282.         CHECK_HRESULT(hRes)
  283.  
  284.         CString cstrTextTemp;
  285.         char v[10];
  286.         memset(v, 0, 10);
  287.         lPsscount++;
  288.         _ltoa(lPsscount,v, 10);
  289.         lPsscount--;
  290. //        AfxMessageBox("PaperSpace wizard tool is runned.");
  291.  
  292.         CPaperSpaceWizard dlg(IDS_DESCRIPTION,NULL, 0);        
  293. //        CString cstrWizCaption;
  294.         cstrText.LoadString (IDS_PSNAMETEMPLATE); 
  295. //        cstrTextTemp = " - Begin";
  296.         cstrText.Insert((cstrText.GetLength ()), " ");
  297.         cstrText.Insert((cstrText.GetLength ()), v);
  298.         dlg.m_PSInfo = & pPSInfo;
  299.         dlg.m_pPss = pPss;        
  300.         dlg.m_pPss->AddRef();        
  301.         
  302.         dlg.m_PSInfo->bPaperOrientation = 0;
  303.         dlg.m_PSInfo->cstrPSpaceName = cstrText;
  304.         
  305.         
  306.         int nResponse = dlg.DoModal();
  307.         nResponse = IDOK;
  308.         if (nResponse == IDOK)
  309.         {
  310.             // TODO: Place code here to handle when the dialog is
  311.             //  dismissed with OK
  312.  
  313.             BSTR bstrPsName;
  314.  
  315.             bstrPsName = pPSInfo.cstrPSpaceName.AllocSysString ();
  316. /*
  317.             hRes = pPss->Add(bstrPsName, &pDisp);
  318.             CHECK_HRESULT(hRes)
  319.             hRes = pDisp->QueryInterface (IID_PaperSpace, (void**)&pPs);
  320.             CHECK_HRESULT(hRes)
  321.  
  322.             hRes = pPs->Activate();
  323.             CHECK_HRESULT(hRes)
  324. */
  325.         
  326.         }
  327.         else if (nResponse == IDCANCEL)
  328.         {
  329.             // TODO: Place code here to handle when the dialog is
  330.             //  dismissed with Cancel
  331.         }
  332.  
  333. /*
  334.         hRes = ThisTool->QueryInterface(IID_Tool, (void **)&m_pTool);
  335.         CHECK_HRESULT(hRes)
  336.  
  337.         hRes = m_pTool->get_Application(&m_pIApplication);
  338.         CHECK_HRESULT(hRes)
  339.  
  340.         hRes = QueryInterface(IID_IPSsWizard, (void**)&m_pITool);
  341.         CHECK_HRESULT(hRes)
  342.         hRes = m_pIApplication->QueryInterface(IID_IToolEvents, (void **)&m_pIToolEvents);
  343.         CHECK_HRESULT(hRes)
  344.         hRes = m_pIToolEvents->ToolChangePrompt(m_pITool,bstrStatusPrompt , FALSE);
  345.         CHECK_HRESULT(hRes)
  346. */
  347.     }
  348.     catch (...)
  349.     {
  350.         TRACE_EXCEPTION("CPSsWizard::Run")
  351.     }
  352.  
  353.     RELEASE(pPs)
  354.     RELEASE(pDisp)
  355.     RELEASE(pPss);
  356.     RELEASE(pDr);
  357.     RELEASE(m_pIApplication);
  358.     return S_OK;
  359. }
  360.  
  361. STDMETHODIMP CPSsWizard::MouseDown(IDispatch *WhichDrawing, IDispatch *WhichView, IDispatch *WhichWindow, short Button, long Shift, long X, long Y, VARIANT_BOOL *Cancel)
  362. {
  363.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  364.  
  365.     // TODO: Add your implementation code here
  366.  
  367.     return S_OK;
  368. }
  369.  
  370. STDMETHODIMP CPSsWizard::MouseUp(IDispatch *WhichDrawing, IDispatch *WhichView, IDispatch *WhichWindow, short Button, long Shift, long X, long Y, VARIANT_BOOL *Cancel)
  371. {
  372.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  373.  
  374.     // TODO: Add your implementation code here
  375.  
  376.     return S_OK;
  377. }
  378.  
  379. STDMETHODIMP CPSsWizard::MouseMove(IDispatch *WhichDrawing, IDispatch *WhichView, IDispatch *WhichWindow, long Shift, long X, long Y, VARIANT_BOOL *pbCancel)
  380. {
  381.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  382.  
  383.     // TODO: Add your implementation code here
  384.  
  385.     return S_OK;
  386. }
  387.  
  388. STDMETHODIMP CPSsWizard::RunTool(IDispatch *ThisTool)
  389. {
  390.     AFX_MANAGE_STATE(AfxGetStaticModuleState())
  391.  
  392.     // TODO: Add your implementation code here
  393.  
  394.     return S_OK;
  395. }
  396. void CPSsWizard::ConnectEvents(IDispatch *ThisTool)
  397. {
  398.  
  399.      HRESULT hRes = S_OK;
  400.  
  401.     if (m_dwEventConnection != 0)
  402.     {
  403. //        AfxMessageBox("Already connected.");
  404.         return;
  405.     }
  406.     
  407.  
  408.     try
  409.     {
  410.  
  411.         DWORD dwEventMask = imsiEventMouseUp
  412. //                             | imsiEventSelectionChange
  413.                              | imsiEventMouseMove
  414.                              | imsiEventMouseDown
  415.                              | imsiEventDrawingDeactivate
  416.                              | imsiEventRunTool
  417.                              | imsiEventBeforeExit;
  418. //                             | imsiEventMouseMove;
  419. //                             | imsiEventPointSnapped;
  420.  
  421.  
  422.         COleVariant var((long)dwEventMask);
  423.         hRes = m_pIApplication->ConnectEvents(ThisTool,
  424.             &var,
  425.             (long*)&m_dwEventConnection);
  426.         
  427.  
  428.         if (FAILED(hRes))
  429.         {
  430.     //        AfxMessageBox("Connection not established.");
  431.             return;
  432.         }
  433.     }
  434.     catch (...)
  435.     {
  436.         TRACE_EXCEPTION("CPSsWizard::ConnectEvents")
  437.     }
  438.  
  439. }
  440.  
  441. void CPSsWizard::DisconnectEvents()
  442. {
  443.  
  444.     if (m_pIApplication == NULL || m_dwEventConnection == 0)
  445.         return;
  446.     try 
  447.     {
  448.  
  449.         HRESULT    hRes = m_pIApplication->DisconnectEvents(m_dwEventConnection);
  450.         CHECK_HRESULT(hRes)
  451.         if (FAILED(hRes))
  452.         {
  453. //            AfxMessageBox("Connection not broken.");
  454.             return;
  455.     
  456.         }
  457.         m_dwEventConnection = 0;
  458.  
  459.     }
  460.  
  461.     catch (...)
  462.     {
  463.         TRACE_EXCEPTION("CPSsWizard::DisconnectEvents")
  464.     }
  465. //    if(m_pIApplication != NULL)
  466. //    {
  467. //        m_pIApplication->Release(); 
  468. //        m_pIApplication = NULL;
  469. //    }
  470.  
  471. }
  472. void CPSsWizard::Destroy()
  473. {
  474. //    RELEASE(m_pView)
  475.  
  476.     CString cstrT;
  477.     cstrT.Empty ();
  478.     BSTR bstrPromt = NULL;
  479.     bstrPromt = cstrT.AllocSysString ();
  480.     m_pIToolEvents->ToolChangePrompt(m_pITool,bstrPromt, FALSE);
  481.  
  482.     RELEASE(m_pIToolEvents)
  483.     DisconnectEvents();
  484.     RELEASE(m_pDragGraphic);
  485.     RELEASE(m_pITool);
  486.     RELEASE(m_pTool);
  487.     RELEASE(m_pIApplication);
  488.         
  489.     m_bRunned = FALSE;
  490.  
  491. }
  492.